retire html_entitize, xml_entitize. (#906)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Thu, 4 Aug 2022 17:39:14 +0000 (11:39 -0600)
committerGitHub <noreply@github.com>
Thu, 4 Aug 2022 17:39:14 +0000 (11:39 -0600)
* retire html_entitize, xml_entitize.

in favor of QString::toHtmlEscaped() and XmlStreamWriter.

* delete obsolete entity struct.

defs.h
html.cc
kml.cc
util.cc

diff --git a/defs.h b/defs.h
index b7d1fc246abc2ba6c5a2c9d39349b3f118e49418..5c88eb486756c4baa40eb2053540ec051ccaa00b 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -1079,8 +1079,6 @@ QDateTime dotnet_time_to_qdatetime(long long dotnet);
 QString get_cache_icon(const Waypoint* waypointp);
 QString gs_get_cachetype(geocache_type t);
 QString gs_get_container(geocache_container t);
-[[deprecated("Use xmlstreamwriter.")]] QString xml_entitize(const QString& str);
-QString html_entitize(const QString& str);
 QString strip_html(const utf_string*);
 QString strip_nastyhtml(const QString& in);
 QString convert_human_date_format(const char* human_datef);    /* "MM,YYYY,DD" -> "%m,%Y,%d" */
diff --git a/html.cc b/html.cc
index 0359a49a2d6bf5a99fbfc596efeb922cbdbdff8b..19cebca0174b89fc7cf94d349ea502dea5fe8499 100644 (file)
--- a/html.cc
+++ b/html.cc
@@ -96,9 +96,9 @@ HtmlFormat::html_disp(const Waypoint* wpt) const
   if (wpt->description != wpt->shortname) {
     if (wpt->HasUrlLink()) {
       *file_out << "<a href=\"" << wpt->GetUrlLink().url_ << "\">"
-                << html_entitize(wpt->description) << "</a>";
+                << wpt->description.toHtmlEscaped() << "</a>";
     } else {
-      *file_out << html_entitize(wpt->description);
+      *file_out << wpt->description.toHtmlEscaped();
     }
     if (!wpt->gc_data->placer.isEmpty()) {
       *file_out << " by " << wpt->gc_data->placer;
@@ -162,7 +162,7 @@ HtmlFormat::html_disp(const Waypoint* wpt) const
         logpart = xml_findfirst(curlog, "groundspeak:finder");
         if (logpart) {
           *file_out << "<span class=\"gpsbabellogfinder\">"
-                    << html_entitize(logpart->cdata) << "</span> on ";
+                    << logpart->cdata.toHtmlEscaped() << "</span> on ";
         }
 
         logpart = xml_findfirst(curlog, "groundspeak:date");
@@ -197,7 +197,7 @@ HtmlFormat::html_disp(const Waypoint* wpt) const
             s = logpart->cdata;
           }
 
-          *file_out << html_entitize(s);
+          *file_out << s.toHtmlEscaped();
         }
 
         *file_out << "</p>\n";
@@ -215,7 +215,7 @@ void
 HtmlFormat::html_index(const Waypoint* wpt) const
 {
   *file_out << "    <a href=\"#" << create_id(waypoint_number) << "\">"
-            << html_entitize(wpt->shortname) << " - " << html_entitize(wpt->description)
+            << wpt->shortname.toHtmlEscaped() << " - " << wpt->description.toHtmlEscaped()
             << "</a><br>\n";
 }
 
diff --git a/kml.cc b/kml.cc
index bf56c1dfff9592d445c216719d10d882ab390b30..9dc7ee3b8ff2d98cf09f23ad9ac3abfaecb69f98 100644 (file)
--- a/kml.cc
+++ b/kml.cc
@@ -1239,7 +1239,7 @@ QString KmlFormat::kml_geocache_get_logs(const Waypoint* wpt) const
       }
 
       r += "<br />";
-      r += html_entitize(s);
+      r += s.toHtmlEscaped();
     }
 
     r += "</p>";
diff --git a/util.cc b/util.cc
index 02ecbd53c32c8b6abb8d10ba3f14c433a9d78308..eeccc39fd51de4f0444fc1018ba73314c16f5acb 100644 (file)
--- a/util.cc
+++ b/util.cc
@@ -1354,120 +1354,6 @@ strip_html(const utf_string* in)
 #endif
 }
 
-struct entity_types {
-  const char* text;
-  const char* entity;
-  int  not_html;
-};
-
-static
-entity_types stdentities[] =  {
-  { "&",       "&amp;", 0 },
-  { "'",       "&apos;", 1 },
-  { "<",       "&lt;", 0 },
-  { ">",       "&gt;", 0 },
-  { "\"",      "&quot;", 0 },
-  { "\x01",    " ", 1 }, // illegal xml 1.0 character
-  { "\x02",    " ", 1 }, // illegal xml 1.0 character
-  { "\x03",    " ", 1 }, // illegal xml 1.0 character
-  { "\x04",    " ", 1 }, // illegal xml 1.0 character
-  { "\x05",    " ", 1 }, // illegal xml 1.0 character
-  { "\x06",    " ", 1 }, // illegal xml 1.0 character
-  { "\x07",    " ", 1 }, // illegal xml 1.0 character
-  { "\x08",    " ", 1 }, // illegal xml 1.0 character
-  // { "\x09", " ", 1 },  legal xml 1.0 character
-  // { "\x0a", " ", 1 },  legal xml 1.0 character
-  { "\x0b",    " ", 1 }, // illegal xml 1.0 character
-  { "\x0c",    " ", 1 }, // illegal xml 1.0 character
-  // { "\x0d", " ", 1 },  legal xml 1.0 character
-  { "\x0e",    " ", 1 }, // illegal xml 1.0 character
-  { "\x0f",    " ", 1 }, // illegal xml 1.0 character
-  { "\x10",    " ", 1 }, // illegal xml 1.0 character
-  { "\x11",    " ", 1 }, // illegal xml 1.0 character
-  { "\x12",    " ", 1 }, // illegal xml 1.0 character
-  { "\x13",    " ", 1 }, // illegal xml 1.0 character
-  { "\x14",    " ", 1 }, // illegal xml 1.0 character
-  { "\x15",    " ", 1 }, // illegal xml 1.0 character
-  { "\x16",    " ", 1 }, // illegal xml 1.0 character
-  { "\x17",    " ", 1 }, // illegal xml 1.0 character
-  { "\x18",    " ", 1 }, // illegal xml 1.0 character
-  { "\x19",    " ", 1 }, // illegal xml 1.0 character
-  { "\x1a",    " ", 1 }, // illegal xml 1.0 character
-  { "\x1b",    " ", 1 }, // illegal xml 1.0 character
-  { "\x1c",    " ", 1 }, // illegal xml 1.0 character
-  { "\x1d",    " ", 1 }, //illegal xml 1.0 character
-  { "\x1e",    " ", 1 }, //illegal xml 1.0 character
-  { "\x1f",    " ", 1 }, //illegal xml 1.0 character
-  { nullptr,   nullptr, 0 }
-};
-
-static
-QString
-entitize(const char* str, bool is_html)
-{
-  char* p;
-  char* tmp;
-  char* xstr;
-
-  entity_types* ep = stdentities;
-  int elen = 0;
-  int ecount = 0;
-
-  /* figure # of entity replacements and additional size. */
-  while (ep->text) {
-    const char* cp = str;
-    while ((cp = strstr(cp, ep->text)) != nullptr) {
-      elen += strlen(ep->entity) - strlen(ep->text);
-      ecount++;
-      cp += strlen(ep->text);
-    }
-    ep++;
-  }
-
-  /* enough space for the whole string plus entity replacements, if any */
-  tmp = (char*) xcalloc((strlen(str) + elen + 1), 1);
-  strcpy(tmp, str);
-
-  if (ecount != 0) {
-    for (ep = stdentities; ep->text; ep++) {
-      p = tmp;
-      if (is_html && ep->not_html)  {
-        continue;
-      }
-      while ((p = strstr(p, ep->text)) != nullptr) {
-        elen = strlen(ep->entity);
-
-        xstr = xstrdup(p + strlen(ep->text));
-
-        strcpy(p, ep->entity);
-        strcpy(p + elen, xstr);
-
-        xfree(xstr);
-
-        p += elen;
-      }
-    }
-  }
-
-  QString rv(tmp);
-  xfree(tmp);
-  return rv;
-}
-
-/*
- * Public callers for the above to hide the absence of &apos from HTML
- */
-
-[[deprecated("Use xmlstreamwriter.")]] QString xml_entitize(const QString& str)
-{
-  return entitize(CSTR(str), false);
-}
-
-QString html_entitize(const QString& str)
-{
-  return entitize(CSTR(str), true);
-}
-
 /*
  * xml_tag utilities
  */